<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>按钮</title>
    <style>
      a {
        display: flex;
        justify-content: center;
        margin-top: 50px;
        text-decoration: none;
      }
      .btn {
        width: 250px;
        height: 30px;
        font-size: 16px;
        padding: 10px;
        text-align: center;
        line-height: 3px;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <a href="https://www.baidu.com/">
        <button class="btn" :disabled="disabled">倒数{{ num }}秒可点击</button>
      </a>
    </div>
    <script src="./vue.js"></script>
    <script>
      let app = new Vue({
        el: "#app",
        data: {
          num: 10,
          disabled: true,
        },
        created() {
          let timer = setInterval(() => {
            this.num--;
            if (this.num < 0) {
              this.num = 0;
              this.disabled = false;
              clearInterval(timer);
            }
          }, 1000);
        },
      });
    </script>
  </body>
</html>
